using System;
using System.Collections;
using System.Net;
using System.Text;
public class QQ_qun_util
{
	public static ArrayList getQunList(string cookie)
	{
		string str = QQ_qun_util.smethod_2(cookie);
		string address = "http://qun.qq.com/cgi-bin/qun_mgr/get_group_list";
		WebClient webClient = new WebClient();
		webClient.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
		webClient.Headers.Add("Origin", "http://qun.qq.com");
		webClient.Headers.Add("X-Requested-With", "XMLHttpRequest");
		webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36");
		webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		webClient.Headers.Add("Referer", "http://qun.qq.com/member.html");
		webClient.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
		webClient.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
		webClient.Headers.Add("Cookie", cookie);
		byte[] array = webClient.UploadData(address, "POST", Encoding.UTF8.GetBytes("bkn=" + str));
		string value = webClient.ResponseHeaders["Content-Encoding"];
		string text;
		if ("gzip".Equals(value))
		{
			text = GzipUtil.zip_to_string(array, Encoding.UTF8);
		}
		else
		{
			text = Encoding.UTF8.GetString(array);
		}
		ArrayList arrayList = new ArrayList();
		int num = 0;
		while ((num = text.IndexOf("\"gc\":", num)) != -1)
		{
			arrayList.Add(new QQqun
			{
				num = StringUtil.subString(text, num, "\"gc\":", ","),
				name = StringUtil.subString(text, num, "\"gn\":\"", "\",\"").Replace("&nbsp;", " "),
				owner = StringUtil.subString(text, num, "\"owner\":", "}")
			});
			num++;
		}
		return arrayList;
	}
	public static ArrayList query_qq_item(string qq, string groupid, string cookie)
	{
		string text = QQ_qun_util.smethod_2(cookie);
		string text2 = "http://qun.qzone.qq.com/cgi-bin/get_group_member?callbackFun=_GroupMember&uin={qq}&groupid={groupid}&neednum=1&r=0.8628084792289883&g_tk={gtk}&ua=Mozilla%2F5.0%20(Windows%20NT%206.1%3B%20WOW64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F31.0.1650.63%20Safari%2F537.36";
		string address = text2.Replace("{qq}", qq).Replace("{groupid}", groupid).Replace("{gtk}", text ?? "");
		WebClient webClient = new WebClient();
		webClient.Headers.Add("Accept", "*/*");
		webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36");
		webClient.Headers.Add("Referer", "http://qun.qzone.qq.com/group");
		webClient.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
		webClient.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
		webClient.Headers.Add("Cookie", cookie);
		byte[] array = webClient.DownloadData(address);
		string value = webClient.ResponseHeaders["Content-Encoding"];
		string text3;
		if ("gzip".Equals(value))
		{
			text3 = GzipUtil.zip_to_string(array, Encoding.UTF8);
		}
		else
		{
			text3 = Encoding.UTF8.GetString(array);
		}
		ArrayList arrayList = new ArrayList();
		int num = 0;
		while ((num = text3.IndexOf("\"iscreator\":", num)) != -1)
		{
			arrayList.Add(new QQItem
			{
				iscreator = int.Parse(StringUtil.subString(text3, num, "\"iscreator\":", ",")),
				ismanager = int.Parse(StringUtil.subString(text3, num, "\"ismanager\":", ",")),
				nick = StringUtil.subString(text3, num, "\"nick\":\"", "\",\"").Trim(),
				uin = StringUtil.subString(text3, num, "\"uin\":", "}"),
				ingrpnum = 1,
				string_2 = "0"
			});
			num++;
		}
		return arrayList;
	}
	public static string smethod_2(string string_0)
	{
		string text = StringUtil.subString(string_0, 0, "skey=", ";");
		int num = 5381;
		for (int i = 0; i < text.Length; i++)
		{
			num += (num << 5) + (int)char.Parse(text.Substring(i, 1));
		}
		int num2 = num & 2147483647;
		return string.Concat(num2);
	}
}
